package cn.tedu.coolshark.practice.controller;

import cn.tedu.coolshark.practice.entity.User;
import cn.tedu.coolshark.practice.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController
public class UserController {

    @Autowired
    UserMapper mapper;

    @RequestMapping("/login")
    public int login(@RequestBody User user, HttpSession session){
        User u = mapper.selectByUsername(user.getUsername());
        if (u!=null){
            if (u.getPassword().equals(user.getPassword())){
                session.setAttribute("user", u);
                return 1; // 登录成功
            }
            return 3; // 密码错误
        }
        return 2; // 用户名不存在
    }


}
